package com.jyxd.web.service.assessment.basic;

import com.jyxd.web.dao.basic.MedOrderExecRecordDao;
import com.jyxd.web.data.basic.MedOrderExec;
import com.jyxd.web.data.basic.MedOrderExecRecord;
import com.jyxd.web.data.user.User;
import com.jyxd.web.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.jyxd.web.util.DateUtil.yyyyMMddSdfToDate;

@Service
@Transactional
public class MedOrderExecRecordService {

    @Autowired
    private MedOrderExecRecordDao medOrderExecRecordDao;

    public boolean insert(MedOrderExec medOrderExec, String dataTime, User user) throws ParseException {
        MedOrderExecRecord medOrderExecRecord = new MedOrderExecRecord();
        medOrderExecRecord.setId(UUIDUtil.getUUID());
        medOrderExecRecord.setDataTime(yyyyMMddSdfToDate(dataTime));
        medOrderExecRecord.setOperatorCode(user.getLoginName());
        medOrderExecRecord.setOrderNo(medOrderExec.getId());
        medOrderExecRecord.setStatus(1);
        medOrderExecRecord.setSyncCount(1);
        return medOrderExecRecordDao.insert(medOrderExecRecord);
    }

    public boolean update(MedOrderExecRecord medOrderExecRecord) {
        return medOrderExecRecordDao.update(medOrderExecRecord);
    }

    public MedOrderExecRecord queryData(String id) {
        return medOrderExecRecordDao.queryData(id);
    }

    public List<MedOrderExecRecord> queryList(Map<String, Object> map) {
        return medOrderExecRecordDao.queryList(map);
    }

    public int queryNum(Map<String, Object> map) {
        return medOrderExecRecordDao.queryNum(map);
    }

    public List<Map<String, Object>> getList(Map<String, Object> map) {
        return medOrderExecRecordDao.getList(map);
    }

    public int getNum(Map<String, Object> map) {
        return medOrderExecRecordDao.getNum(map);
    }

    public MedOrderExecRecord queryByDateAndMedId(String medId, String dateDay) {
        Map map = new HashMap();
        map.put("orderNo", medId);
        map.put("dateDay", dateDay);
        return medOrderExecRecordDao.queryByDateAndMedId(map);
    }
}
